<?php
include_once('includes.php'); 

if(isset($_GET["id"]) && $_GET["id"]>0 )
{
	$id = (int) $_GET["id"];
	$sql = "select * from competition where id=".addslashes($id);
	$competition=db_fetch_one($sql);

}	
else
{
	Header("Location: /");
	exit;
}	
?>

<?php include_once('includes/header.php'); 	 ?>

<h1 class="header"><?php echo $competition->name;?></h1>
<div class="competition"> 
	<div class="logo"><img src="<?php echo $competition->logo;?>" alt="<?php echo $competition->name;?>"/></div>
	<span class="desc"><?php echo $competition->description;?></span>
</div>


<?php
//start box matchs Now playing
$sql = "select * from matchs where competition_id = ".$competition->id." and status=1  order by kick_off asc ";
$matchs=db_fetch_all($sql);
if(count($matchs)>0) 
{
?>	
<div class="cbox playing clearfix">
	<span class="title">Các trận đang diễn ra</span>
	<div class="content">
		<ul class="matchs">
	<?php 
	
	foreach($matchs as $match)
	{
		$local_kick_off = convertTimeToLocal($match->kick_off,$match->timezone);
	?>
		<li> 
			<div class="kick-off"><?php echo formatOutputDate($local_kick_off); ?></div>
			<div class="vs">	<a href="/match/<?php echo $match->id."-".clean_entities($match->versus); ?>"><strong><?php echo $match->versus; ?></strong></a>  </div>
			
		</li>
	<?php
	}
	?>
		</ul>
	</div>
</div>	
<?php
}

//start box matchs Upcoming
$sql = "select * from matchs where competition_id = ".$competition->id." and status=0  order by status asc ,kick_off asc ";
$matchs=db_fetch_all($sql);
if(count($matchs)>0) 
{
?>

<div class="cbox clearfix">
	<span class="title">Lịch trực tiếp các trận sắp diễn ra</span>
	<div class="content">
		<ul class="matchs">
	<?php 
	foreach($matchs as $match)
	{
		$local_kick_off = convertTimeToLocal($match->kick_off,$match->timezone);
	?>
		<li> 
			<div class="kick-off"><?php echo formatOutputDate($local_kick_off); ?></div>
			<div class="vs">	<a href="/match/<?php echo $match->id."-".clean_entities($match->versus); ?>"><strong><?php echo $match->versus; ?></strong></a>  </div>
			<div class="time-count"><?php echo remainTime($local_kick_off,'<div class="remainingTime countdown"><span class="NoDisplay">Trận đấu sẽ diễn ra sau <b class="remainingDay">%d </b> ngày <b class="remainingHour">%h </b> giờ <b class="remainingMinute">%m </b> phút <b class="remainingSecond">0</b> giây</span><span class="TimeDisplay"><span class="Text ShortText"></span><span class="Time"></span></span></div>'); ?></div>
		</li>
	<?php
	}
	?>
		</ul>
	</div>
</div>
<?php
}
?>

<?php
$sql = "select  highlights.id as hid, highlights.* ,matchs.*, competition.name as cname, competition.id as cid, competition.classicon as cicon from   highlights left join matchs on highlights.match_id = matchs.id left join competition on matchs.competition_id = competition.id where  status=2 and competition.id=".$competition->id." order by matchs.kick_off desc limit 10 ";
$matchs=db_fetch_all($sql);

if(count($matchs)>0) 
{
?>

<div class="cbox clearfix">
	<span class="title">Video bàn thắng</span>
	<div class="content">
		<ul class="matchs">
	<?php 
	foreach($matchs as $match)
	{
		$local_kick_off = convertTimeToLocal($match->kick_off,$match->timezone);
	
		list($team1, $team2 ) = split('-',$match->versus);
		$team1 = trim($team1);
		$team2 = trim($team2);
	?>
		<li> 
			<div class="kick-off"><?php echo formatOutputDate($local_kick_off); ?></div>
			<div class="vs">	<a href="/match/<?php echo $match->id."-".clean_entities($match->versus); ?>"><strong><?php echo $team1." ".$match->score." ".$team2;?></strong></a>  </div>
			
		</li>
	<?php
	}
	?>
		</ul>
		
	</div>
</div>
<?php
}
?>



<?php include_once('includes/footer.php'); 	 ?>